// pages/function/index.js
const APP = getApp();
//常量
const ACTIONS_LIST_DATA = [
  [
    {
      title: '单列表',
      icon: '/pages/res/common/icon_list_item1.png',
      link: '/pages/function/sub/list',
      open_type:'navigate',
      extra_data:{}
    },
    {
      title: '单列表+搜索',
      icon: '/pages/res/common/icon_list_item1.png',
      link: '/pages/function/sub/list-search',
      open_type:'navigate',
      extra_data:{}
    },
    {
      title: 'Tab列表',
      icon: '/pages/res/common/icon_list_item1.png',
      link: '/pages/function/sub/tab-list',
      open_type:'navigate',
      extra_data:{}
    },
    {
      title: 'Tab列表+搜索',
      icon: '/pages/res/common/icon_list_item1.png',
      link: '/pages/function/sub/tab-list-search',
      open_type:'navigate',
      extra_data:{}
    },
  ],
  [
    {
      title: '登录/注册',
      icon: '/pages/res/common/icon_list_item2.png',
      link: '/pages/function/sub/login-index',
      open_type:'navigate',
      extra_data:{}
    }
  ],
];

Page({

  /**
   * 页面的初始数据
   */
  data: {
      //固定参数
      //分页变量
      //逻辑变量
      dataActionList:ACTIONS_LIST_DATA
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 逻辑区域
   */

   //点击功能模块
  clickAction:function(event){
    let _this = this,dataset = event.currentTarget.dataset;
    let actionInfo = _this.data.dataActionList[dataset.pidx][dataset.idx];
    if(actionInfo.open_type == 'switchTab'){
      wx.setStorage({
        data: JSON.stringify(actionInfo.extra_data),
        key: 'nav_flag',
        success:function(res){
          wx.switchTab({
            url: actionInfo.link,
          });
        }
      });
    }else if(actionInfo.open_type == 'navigate'){
      wx.navigateTo({
        url: actionInfo.link+'?param='+APP.apptool.encodeJsonStr(actionInfo.extra_data),
      });
      }else{
        wx.navigateTo({
          url: actionInfo.link+'?param='+APP.apptool.encodeJsonStr(actionInfo.extra_data),
        });
      }
    },
})